﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NNLInterface
{
    public partial class frmRptGloParameter : NNLInterface.frmBaseXC
    {
        string strSQL = "";
        public frmRptGloParameter()
        {
            InitializeComponent();
        }

        private void frmRptGloParameter_Load(object sender, EventArgs e)
        {
            //取出数据库中的数据，如没有，则显示0
            strSQL = "SELECT * FROM RptParameter rp";
            DataTable dtParameter = accessdb.GetRecord(strSQL).ADODataRst;

            if(dtParameter.Rows.Count>=1)
            {
                this.numN1WorkDays.Value = (decimal)dtParameter.Rows[0]["N1WorkDays"];
                this.numN2WorkDays.Value = (decimal)dtParameter.Rows[0]["N2WorkDays"];
                this.numN3WorkDays.Value = (decimal)dtParameter.Rows[0]["N3WorkDays"];
                this.numN4WorkDays.Value = (decimal)dtParameter.Rows[0]["N4WorkDays"];
                this.numN5WorkDays.Value = (decimal)dtParameter.Rows[0]["N5WorkDays"];
                this.numN6WorkDays.Value = (decimal)dtParameter.Rows[0]["N6WorkDays"];

                this.numN1WeekDays.Value = (decimal)dtParameter.Rows[0]["N1WeekDays"];
                this.numN2WeekDays.Value = (decimal)dtParameter.Rows[0]["N2WeekDays"];
                this.numN3WeekDays.Value = (decimal)dtParameter.Rows[0]["N3WeekDays"];
                this.numN4WeekDays.Value = (decimal)dtParameter.Rows[0]["N4WeekDays"];
                this.numN5WeekDays.Value = (decimal)dtParameter.Rows[0]["N5WeekDays"];
                this.numN6WeekDays.Value = (decimal)dtParameter.Rows[0]["N6WeekDays"];

                this.numN1WorkHours.Value = (decimal)dtParameter.Rows[0]["N1WorkHours"];
                this.numN2WorkHours.Value = (decimal)dtParameter.Rows[0]["N2WorkHours"];
                this.numN3WorkHours.Value = (decimal)dtParameter.Rows[0]["N3WorkHours"];
                this.numN4WorkHours.Value = (decimal)dtParameter.Rows[0]["N4WorkHours"];
                this.numN5WorkHours.Value = (decimal)dtParameter.Rows[0]["N5WorkHours"];
                this.numN6WorkHours.Value = (decimal)dtParameter.Rows[0]["N6WorkHours"];

            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                //保存数据
                if (DevExpress.XtraEditors.XtraMessageBox.Show("确定要保存数据吗(Y/N)?", common.sysParameter.MessageInf, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;

                //保存数据
                strSQL = "IF NOT  EXISTS(SELECT rp.N1WorkDays FROM RptParameter rp) \n"
                               + "INSERT INTO RptParameter \n"
                               + "( \n"
                               + "	N1WorkDays, \n"
                               + "	N2WorkDays, \n"
                               + "	N3WorkDays, \n"
                               + "	N4WorkDays, \n"
                               + "	N5WorkDays, \n"
                               + "	N6WorkDays, \n"

                               + "	N1WeekDays, \n"
                               + "	N2WeekDays, \n"
                               + "	N3WeekDays, \n"
                               + "	N4WeekDays, \n"
                               + "	N5WeekDays, \n"
                               + "	N6WeekDays, \n"

                               + "	N1WorkHours, \n"
                               + "	N2WorkHours, \n"
                               + "	N3WorkHours, \n"
                               + "	N4WorkHours, \n"
                               + "	N5WorkHours, \n"
                               + "	N6WorkHours \n"
                               + ") \n"
                               + "VALUES \n"
                               + "( \n"
                               + this.numN1WorkDays.Value.ToString() + ",\n"
                               + this.numN2WorkDays.Value.ToString() + ",\n"
                               + this.numN3WorkDays.Value.ToString() + ",\n"
                               + this.numN4WorkDays.Value.ToString() + ",\n"
                               + this.numN5WorkDays.Value.ToString() + ",\n"
                               + this.numN6WorkDays.Value.ToString() + ",\n"

                               + this.numN1WeekDays.Value.ToString() + ",\n"
                               + this.numN2WeekDays.Value.ToString() + ",\n"
                               + this.numN3WeekDays.Value.ToString() + ",\n"
                               + this.numN4WeekDays.Value.ToString() + ",\n"
                               + this.numN5WeekDays.Value.ToString() + ",\n"
                               + this.numN6WeekDays.Value.ToString() + ",\n"

                               + this.numN1WorkHours.Value.ToString() + ",\n"
                               + this.numN2WorkHours.Value.ToString() + ",\n"
                               + this.numN3WorkHours.Value.ToString() + ",\n"
                               + this.numN4WorkHours.Value.ToString() + ",\n"
                               + this.numN5WorkHours.Value.ToString() + ",\n"
                               + this.numN6WorkHours.Value.ToString() + "\n"
                               + ") \n"
                               + "ELSE \n"
                               + "	UPDATE rp SET rp.N1WorkDays = " + this.numN1WorkDays.Value.ToString() + ",\n"
                               + "           rp.N2WorkDays = " + this.numN2WorkDays.Value.ToString() + ",\n"
                               + "           rp.N3WorkDays = " + this.numN3WorkDays.Value.ToString() + ",\n"
                               + "           rp.N4WorkDays =" + this.numN4WorkDays.Value.ToString() + ",\n"
                               + "           rp.N5WorkDays =" + this.numN5WorkDays.Value.ToString() + ",\n"
                               + "           rp.N6WorkDays = " + this.numN6WorkDays.Value.ToString() + ",\n"

                               + "           rp.N1WeekDays = " + this.numN1WeekDays.Value.ToString() + ",\n"
                               + "           rp.N2WeekDays = " + this.numN2WeekDays.Value.ToString() + ",\n"
                               + "           rp.N3WeekDays =" + this.numN3WeekDays.Value.ToString() + ",\n"
                               + "           rp.N4WeekDays =" + this.numN4WeekDays.Value.ToString() + ",\n"
                               + "           rp.N5WeekDays = " + this.numN5WeekDays.Value.ToString() + ",\n"
                               + "           rp.N6WeekDays = " + this.numN6WeekDays.Value.ToString() + ",\n"


                               + "           rp.N1WorkHours =" + this.numN1WorkHours.Value.ToString() + ",\n"
                               + "           rp.N2WorkHours = " + this.numN2WorkHours.Value.ToString() + ",\n"
                               + "           rp.N3WorkHours = " + this.numN3WorkHours.Value.ToString() + ",\n"
                               + "           rp.N4WorkHours = " + this.numN4WorkHours.Value.ToString() + ",\n"
                               + "           rp.N5WorkHours = " + this.numN5WorkHours.Value.ToString() + ",\n"
                               + "           rp.N6WorkHours = " + this.numN6WorkHours.Value.ToString() + "\n"
                               + "           FROM RptParameter rp";
                accessdb.RsChange(strSQL);
                DevExpress.XtraEditors.XtraMessageBox.Show("数据已保存!", common.sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, common.sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

           

        }
    }
}
